package com.fc.library.fresco;

import android.text.TextUtils;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * Created by fc on 2017/11/14.
 */

public class SystemUtil {

    private static boolean highPerformance = true;
    private static final long GB = 1024 * 1024 * 1024;
    public static final long MB = 1024 * 1024;
    private static final long KB = 1024;

    static boolean isHighPerformance() {
        return highPerformance;
    }

    static {
        long mem = SystemUtil.getmem_TOLAL() * SystemUtil.KB;
        highPerformance = mem >= 1.5f * SystemUtil.GB;
    }

    // 获得总内存
    private static long getmem_TOLAL() {
        long mTotal = 0;
        // /proc/meminfo读出的内核信息进行解释
        String path = "/proc/meminfo";
        String content = null;
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(path), 8);
            String line;
            if ((line = br.readLine()) != null) {
                content = line;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        // beginIndex
        if (!TextUtils.isEmpty(content)) {
            int begin = content.indexOf(':');
            // endIndex
            int end = content.indexOf('k');
            // 截取字符串信息

            content = content.substring(begin + 1, end).trim();
            mTotal = Integer.parseInt(content);
        }


        return mTotal;
    }
}